package com.tjh.springbootapi.service;

import com.koala.apiprototype.db.BaseService;
import com.tjh.springbootapi.entity.UserInfo;
import com.tjh.springbootapi.mapper.UserInfoMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

/**
 * 服务类
 * Generated on 2020-03-22
 */
@Service
public class UserInfoService extends BaseService<UserInfoMapper, UserInfo> {

    @Transactional
    public HashMap importUserInfo(List<UserInfo> userInfoList) {
        List<UserInfo> errUserInfoList = new ArrayList<>();
        HashMap hashMap = new HashMap();
        //成功的条数
        Integer successCount = 0;
        if (!CollectionUtils.isEmpty(userInfoList)) {
            for (UserInfo userInfo : userInfoList) {
                String id = UUID.randomUUID().toString().replace("-", "").toUpperCase();
                userInfo.setId(id);
            }
            successCount = this.insertList(userInfoList);
        }

        hashMap.put("successCount", successCount);
        hashMap.put("errUserInfoList", errUserInfoList);
        return hashMap;
    }

}
